import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Homework {
    static class myComparator implements Comparator<int[]> {
        //按起点递增排序
        public int compare(int[] a,int[] b){
            return a[1]-b[1];
        }
    }
    public static int greedyActivitySelector(int[][] act){
        //每次选择最早结束的活动
        int num=1;
        int i=0;
        for (int j = 1; j <act.length ; j++) {
            if(act[j][0] >=  act[i][1]){
                i=j;
                num++;
            }
        }
        return num;
    }

    public static void main(String[] args) {
        //这里你可以输入活动的总数量
        Scanner scanner=new Scanner(System.in);
        int number=scanner.nextInt();
        int[][] act=new int[number][2];
        int idx=0;
        //在这里你可以自定义输入活动的开始时间以及结束时间
        for (int i = 0; i <act.length ;i++) {
            act[i][0]=scanner.nextInt();
            act[i][1]=scanner.nextInt();
        }
        //按照活动截止时间从小到大排序
        myComparator mycomparator=new myComparator();
        Arrays.sort(act,mycomparator);
        int ret=greedyActivitySelector(act);
        System.out.println(ret);
    }
}
